#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

bool isValidSudoku(vector<vector<char>>& board) {
    int rows[9][9];
    int col[9][9];
    int sub[3][3][9];

    memset(rows, 0, sizeof rows);
    memset(col, 0, sizeof col);
    memset(sub, 0, sizeof sub);

    for (int i = 0; i < 9; i++)
        for (int j = 0; j < 9; j++)
        {
            char c = board[i][j];
            if (c != '.')
            {
                int idx = c - '0' - 1;
                rows[i][idx]++;
                col[j][idx]++;
                sub[i / 3][j / 3][idx]++;
                if (rows[i][idx] > 1 || col[j][idx] > 1 || sub[i / 3][j / 3][idx] > 1)
                    return false;
            }
        }
    return true;
}